//
//  LoginCompanysViewCell.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/10.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "LoginCompanysViewCell.h"

@interface LoginCompanysViewCell()

@property(nonatomic,strong)UILabel *companyName;
@property(nonatomic,strong)UILabel *groupName;
@property(nonatomic,strong)UILabel *statusName;
@property(nonatomic,strong)UILabel *userTypeName;

@property(nonatomic,strong)UIImageView*brandLogo;
@property(nonatomic,strong)UIButton*chooseBtn;
@property(nonatomic,strong)UIButton*chooseBtn1;
@property(nonatomic,strong)UIButton*chooseBtn2;
@property(nonatomic,strong)UIButton*chooseBtn3;
@property(nonatomic,strong)UIButton*chooseBtn4;
@property(nonatomic,strong)UILabel *lineLabel;


@end
@implementation LoginCompanysViewCell

@synthesize mDelegate;
- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
           }
    
    return self;
    
}
-(void)createView
{
    self.brandLogo=[[UIImageView alloc] init];
    [self.brandLogo.layer setCornerRadius:30.0];
    [self.brandLogo.layer setBorderWidth:0.5];
    [self.brandLogo.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0.93, 0.93, 0.93, 0.93 });
    [self.brandLogo.layer setBorderColor:colorref2];
    [self addSubview:self.brandLogo];
    self.groupName=[[UILabel alloc] init];
    self.groupName.font= [UIFont systemFontOfSize:16];
    self.groupName.textColor=[UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0];
    [self addSubview:self.groupName];
    
   
   
    
    self.userTypeName=[[UILabel alloc] init];
    self.userTypeName.backgroundColor=luseColor;
    self.userTypeName.font= [UIFont systemFontOfSize:13.5];
    [self.userTypeName.layer setCornerRadius:1];
    [self.userTypeName.layer setBorderWidth:0];
    [self.userTypeName.layer setMasksToBounds:YES];
    self.userTypeName.textColor=[UIColor whiteColor];
    self.userTypeName.textAlignment=NSTextAlignmentCenter;
    [self addSubview:self.userTypeName];
    
    
    self.chooseBtn1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-85, 50, 75, 25)];
    [self.chooseBtn1 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [self addSubview:self.chooseBtn1];
    
    self.lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 99.55, ScreenWidth-20, 0.40)];
    self.lineLabel.textColor=[UIColor clearColor];
    [self.lineLabel setBackgroundColor:qianhuiColor];
    [self addSubview:self.lineLabel];
    
}
-(void)setModel:(LoginCompanysModel *)model
{
    [self createView];
    [self setViewAutoLayout];

    [self.brandLogo setImageWithURL:[NSURL URLWithString:model.brandLogo]placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];
    self.lineLabel.text=[NSString stringWithFormat:@" %@ ",model.userTypeName];
    
 
    NSString *s1 =[NSString stringWithFormat:@"%@",model.companyName];
    UIFont *font1 = [UIFont systemFontOfSize:13];
    CGSize size1 = CGSizeMake(ScreenWidth-90-85, 2000);
    CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    
    
    self.companyName=[[UILabel alloc] initWithFrame:CGRectMake(85, 55, ScreenWidth-90-85, labelsize1.height)];
    self.companyName.text=model.companyName;
    self.companyName.numberOfLines=0;
    self.companyName.font= [UIFont systemFontOfSize:13];
    self.companyName.textColor=shenhuiColor;
    [self addSubview:self.companyName];

    
    
    
    self.userTypeName.text=[NSString stringWithFormat:@"%@ ",model.userTypeName];
    self.groupName.text=model.groupName;


    if ([[NSString stringWithFormat:@"%@",  model.isActive] isEqualToString:@"1"]&&[[NSString stringWithFormat:@"%@",  model.status] isEqualToString:@"Y"]) {//当前门店

        self.chooseBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-95, 0, 75, 25)];
        [self.chooseBtn2 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        self.chooseBtn2.center= self.chooseBtn1.center;
        [self.chooseBtn2 setBackgroundImage:[UIImage imageNamed:@"dangqianmendian"] forState:UIControlStateNormal];
        [self.chooseBtn2 setTitle:@"当前门店" forState:UIControlStateNormal];
        self.chooseBtn2. titleLabel.font=[UIFont systemFontOfSize:13];
        [self.chooseBtn2 setTitleColor:[UIColor colorWithRed:252/255.0 green:102/255.0 blue:33/255.0 alpha:1] forState:UIControlStateNormal];
        self.chooseBtn2.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
        [self.chooseBtn2.layer setCornerRadius:2.0]; //设置矩圆角半径
        [self.chooseBtn2.layer setBorderWidth:0.05];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){252/255.0, 102/255.0, 33/255.0, 1.0});
        [self.chooseBtn2.layer setBorderColor:tureBTncolorref];//边框颜色
        [self addSubview:self.chooseBtn2];
        
    }else{
        
        
 if ([[NSString stringWithFormat:@"%@",  model.status] isEqualToString:@"Y"]){//切换门店
        
            self.chooseBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-95, 0, 75, 25)];
            [self.chooseBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
            self.chooseBtn.center= self.chooseBtn1.center;
            [self.chooseBtn setTitle:@"切换门店" forState:UIControlStateNormal];
            self.chooseBtn. titleLabel.font=[UIFont systemFontOfSize:13];
            [self.chooseBtn setTitleColor:luseColor forState:UIControlStateNormal];
            self.chooseBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            [self.chooseBtn.layer setCornerRadius:2.0]; //设置矩圆角半径
            [self.chooseBtn.layer setBorderWidth:0.40];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){90/255.0, 130/255.0, 26/255.0, 1.0});
            [self.chooseBtn.layer setBorderColor:tureBTncolorref];//边框颜色
            [self addSubview:self.chooseBtn];
            
            self.chooseBtn3=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-95, 0, 75, 90)];
            [self.chooseBtn3 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
            self.chooseBtn3.center= self.chooseBtn1.center;
            [self.chooseBtn3 setTitle:model.scId forState:UIControlStateNormal];
            [self.chooseBtn3 addTarget:self action:@selector(goBtn:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.chooseBtn3];
 }
 else if ([[NSString stringWithFormat:@"%@",  model.status] isEqualToString:@"W"]||[[NSString stringWithFormat:@"%@",  model.status] isEqualToString:@"N"]){//禁用或者认证中
 
     
     self.chooseBtn4=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-95, 0, 75, 25)];
     [self.chooseBtn4 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
     self.chooseBtn4.center= self.chooseBtn1.center;
     [self.chooseBtn4 setTitle:model.statusName forState:UIControlStateNormal];
     self.chooseBtn4. titleLabel.font=[UIFont systemFontOfSize:13];
     [self.chooseBtn4 setTitleColor:shenhuiColor forState:UIControlStateNormal];
     self.chooseBtn4.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
     [self.chooseBtn4.layer setCornerRadius:2.0]; //设置矩圆角半径
     [self.chooseBtn4.layer setBorderWidth:0.40];   //边框宽度
     CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){102/255.0, 102/255.0, 102/255.0, 1.0});
     [self.chooseBtn4.layer setBorderColor:tureBTncolorref];//边框颜色
     [self addSubview:self.chooseBtn4];
    
 }
        
}
}
-(void)goBtn:(UIButton*)sender{
    
    [mDelegate switchStores:sender.titleLabel.text];
    
}

-(void)setViewAutoLayout
{
    
    [self.brandLogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@60);
        make.width.equalTo(@60);
        make.top.equalTo(self.mas_top).with.offset(20);
    }];
    
    [self.groupName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.brandLogo.mas_right).with.offset(10);
        make.height.equalTo(@16);
        make.top.equalTo(self.mas_top).with.offset(32.5);
    }];
    
//    [self.companyName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.brandLogo.mas_right).with.offset(10);
//        make.left.equalTo(self.brandLogo.mas_right).with.offset(10);
//        make.height.equalTo(@16);
//        make.top.equalTo(self.mas_top).with.offset(25+30);
//    }];
//    
    
    [self.userTypeName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.groupName.mas_right).with.offset(5);
        
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.groupName.mas_centerY) ;
    }];
    
    
//    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).with.offset(10);
//        make.right.equalTo(self.mas_right).with.offset(-10) ;
//        
//        make.height.equalTo(@0.5);
//        
//        make.top.equalTo(self.mas_top).with.offset(99.5);
//        
//    }];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
